package com.bknow.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bknow.model.ManagerUserInfo;
import com.bknow.model.ResultBean;

@Controller
//用户管理
public class UserManagerController {

	@PostMapping("manager_login")
	@ResponseBody
	public ResultBean<ManagerUserInfo> managerLogin(@RequestBody ManagerUserInfo managerUserInfo,HttpSession session){
		if(!"admin".equals(managerUserInfo.getmName())||!"123456".equals(managerUserInfo.getmPwd())) {
			return new ResultBean<>(401, "用户名或密码错误", null);
		}else {
			session.setAttribute("managerUserInfo", managerUserInfo);
			return new ResultBean<>(200, "登录成功", managerUserInfo);
		}
	}

	//获取用户信息
	@GetMapping("getMangerInfo")
	@ResponseBody
	public ResultBean<ManagerUserInfo> getMangerInfo(HttpSession session){
		ManagerUserInfo userInfo = (ManagerUserInfo) session.getAttribute("managerUserInfo");
		return new ResultBean<>(200, "session", userInfo);
	}
	//销毁session
	@GetMapping("mlogout")@ResponseBody
	public ResultBean<ManagerUserInfo> logout(HttpSession session){
		session.invalidate();
		return new ResultBean<>(200, "session", null);
	}
}
